package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Question;
import cn.wolfcode.trip.base.mapper.QuestionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IQuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QuestionServiceImpl implements IQuestionService {

    @Autowired
    private QuestionMapper questionMapper;

    public void save(Question question) {
        questionMapper.insert(question);
    }

    public PageInfo<Question> listAll(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        return new PageInfo<>(questionMapper.selectForList(qo));
    }

    public Question getById(Long questionId) {
        return questionMapper.selectByPrimaryKey(questionId);
    }

    public void updateAnswerCount(int answerCount, Long id) {
        questionMapper.updateAnswerCount(answerCount,id);
    }

}
